﻿using DevExpress.XtraEditors;
using SX_MesProject.Dtos.LJQDtos;
using SX_MesProject.Dtos;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static SX_MesProject.HttpClientHelper;

namespace SX_MesProject.ProcessManage
{
    public partial class ProcedureAdd : DevExpress.XtraEditors.XtraForm
    {
        public delegate Task LoadData();
        public event LoadData OnLoadData;
        public ProcedureAdd()
        {
            InitializeComponent();
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            AddProcess();
        }
        private async void AddProcess()
        {
            try
            {
                ProcessAddInPut process = new ProcessAddInPut();
                process.Procedure_name = this.textEdit1.Text;
                process.Procedure_explain = this.memoEdit1.Text;
                process.Procedure_state = this.checkEdit1.Checked==true?1:0;
                var list = await HttpClientHelper.RequestUrl<ProcessAddInPut, ResponseDto<int>>("https://localhost:44556/", "InsertProcess", MethodType.POST, process);
                var res = list;
                if (list.Code == 200)
                {
                    MessageBox.Show("添加成功！");
                    //执行事件，调用父窗体的LoadData方法
                    OnLoadData?.Invoke();
                    //if (OnLoadData != null) OnLoadData.Invoke();
                    this.Close();
                }
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }

        private void ProcedureAdd_Load(object sender, EventArgs e)
        {
            
        }
    }
}